<template>
  <div class="delConnect">
    <div class="tip">是否移除已选应用</div>
  </div>
</template>

<script>
import treeApi from '@/api/treeApi'
export default {
  data() {
    return {}
  },
  props: {
    modelForm: {
      type: Object,
      default: () => {}
    },
    selectedRowKeys: {
      type: Array,
      default: () => []
    },
    dcPeriod: {
      type: String,
      default: ''
    }
  },
  methods: {
    save() {
      let params = {
        node: {
          id: this.modelForm.id,
          tenantCode: this.modelForm.tenantCode,
          nodeType: 'standard',
          nodeCode: this.modelForm.nodeCode,
          nodeName: this.modelForm.nodeName,
          nodePath: this.modelForm.nodePath,
          parentId: this.modelForm.parentId,
          nodeLevel: 0
        },
        systemVoList: this.selectedRowKeys,
        buCode: this.$store.state.userBu.key,
        dcPeriod: this.dcPeriod || this.$store.state.writeablePeriod,
        treeCode: 'GJ-' + this.$store.state.userBu.key
      }
      treeApi.deleteSysConnect(params).then(res => {
        if(res.code !== 200){
          this.$message.error({
            content: res.msg,
            duration: 3
          })
          return
        }
        this.$message.success({
          content: '删除成功',
          duration: 3
        })
        this.modelForm.ext1 = JSON.stringify(JSON.parse(this.modelForm.ext1).filter(item =>
          !this.selectedRowKeys.some(i => item.sysCode === i.sysCode)
        ))
        this.$emit("Close", this.modelForm)
      }).catch(err => {
        this.$emit("Close",params)
      })
    }
  },
  computed: {
    actions() {
      return [
        {
          text: '取消',
          // icon: "edit",
          handle: () => this.$emit("Close"),
          loading: false
        },
        {
          text: '确认',
          theme: "primary",
          handle: () => {
            this.save('formValidate');
          },
        }
      ];
    },
  },
  created() {
    this.$emit("SetTitle", "移除关联");
    this.$emit("SetPageMinHeight", 100);
    this.$emit("SetPageActions", this.actions);
  }
}
</script>

<style lang="less" scoped>
.tip {
  font-size: 16px;
}
</style>